<template>
	<view class="container">
		<!-- 背景图片 -->
		<image src="" mode="" class="bg"></image>

		<!-- 邀请方式 -->
		<view class="funciton-list">
			<view class="funciton-item" v-for="(item,index) in headListContentList" :key="index">
				<image :src="item.icon" mode=""></image>
				<p class="text">{{item.text}}</p>
			</view>
		</view>
		<!-- 邀请码 -->
		<view class="invite-code-box">
			<view class="invite-code">
				<p class="code-text">专属邀请码 <span>!</span></p>
				<p class="code-main">{{userInfo.salt}} <span>复制</span></p>
			</view>
		</view>
		<!-- 邀请我的人 -->
		<view class="invited-list">
			<view class="title">
				邀请我的人
			</view>
			<view class="invited-item" v-if="puserInfo === {}">
				<image :src="puserInfo.avatar" mode="" class="avatar"></image>
				<view class="user-info">
					<p class="nick_name">{{puserInfo.nickname}}（{{puserInfo.username}}）</p>
					<p class="noreal" v-if="1 ==1 ">未认证车主</p>
					<p class="real" v-if="1 ==2">已认证车主</p>
					<p class="time">{{new Date(puserInfo.createtime).toLocaleString()}}</p>
				</view>
			</view>
			<view class="nopuser">
				您没有邀请人
			</view>
		</view>
		<!-- 我邀请的人 -->
		<view class="invited-list">
			<view class="title">
				我邀请的人
			</view>
			<view class="inviting-item" v-for="item in puserList" :key="item.id">
				<image :src="item.avatar" mode="" class="avatar"></image>
				<view class="user-info">
					<p class="nick_name">{{item.nickname}}</p>
					<p class="phone">{{item.username}}</p>
				</view>
				<image src="../../static/images/RightArrow.png" mode="" class="arrow"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState({
				userInfo: state => state.userInfo
			})
		},
		data() {
			return {
				headListContentList: [{
						icon: '../../static/images/lianjie.png',
						text: '链接邀请'
					},
					{
						icon: '../../static/images/haibao.png',
						text: '海报邀请'
					},
					{
						icon: '../../static/images/qr-code.png',
						text: '二维码邀请'
					}
				],
				// 邀请我的人信息
				puserInfo: {},
				// 我邀请的人信息
				puserList: []

			}
		},
		methods: {
			// 获取邀请我的人
			getPusherMy() {
				this.$http.post('api/index/puserMy', {}, {
					log: true,
					header: {
						'content-type': 'application/json'
					}
				}).then(res => {
					console.log(res.data);
					// this.puserInfo = res.data[0]
				})
			},
			// 获取我邀请的人
			getPuserList() {
				this.$http.post('api/index/puserList', {}, {
					log: true,
					header: {
						'content-type': 'application/json'
					}
				}).then(res => {
					this.puserList = res.data
				})
			},
		},
		mounted() {
			uni.showLoading({})
			this.getPusherMy()
			this.getPuserList()
			uni.hideLoading()
			this.getInviteCode()
		}

	}
</script>

<style lang="scss" scoped>
	.container {
		background-color: #f9fafc;

		.bg {
			background: #000;
			width: 100%;
			height: 250rpx;
			margin-bottom: 100rpx;
		}

		.funciton-list {
			display: flex;
			justify-content: space-between;
			background: #fff;
			width: 80%;
			padding: 40rpx;
			border-radius: 10rpx;
			box-shadow: 0px 2px 5px rgba(99, 99, 99, 0.2);
			position: fixed;
			left: 50%;
			transform: translateX(-50%);
			top: 15%;

			.funciton-item {
				width: 30%;
				text-align: center;

				image {
					width: 45rpx;
					height: 45rpx;
				}

				.text {
					font-size: 12px;
					margin-top: 5px;
				}
			}
		}

		.invite-code-box {
			display: flex;
			justify-content: center;

			.invite-code {
				background-color: #edf0f7;
				width: 80%;
				padding: 20rpx 40rpx;
				font-size: 14px;
				display: flex;
				justify-content: space-between;

				.code-text {
					display: flex;
					align-items: center;

					span {
						font-size: 10px;
						width: 25rpx;
						height: 25rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						background-color: #999;
						color: #fff;
						border-radius: 30rpx;
						font-size: 8px;
						margin-left: 10rpx;
					}
				}

				.code-main {
					font-size: 16px;
					font-weight: bold;
					display: flex;
					align-items: center;

					span {
						font-size: 12px;
						margin-left: 10rpx;
						border: 1px solid #f3edd5;
						font-weight: 400;
						color: orange;

					}
				}
			}
		}

		.invited-list {
			padding: 40rpx;

			.title {
				font-weight: bold;
				margin-bottom: 60rpx;
			}

			.invited-item {
				display: flex;
				align-items: center;
				gap: 20rpx;

				.avatar {
					height: 100rpx;
					width: 100rpx;
				}

				.user-info {
					display: flex;
					flex-direction: column;
					gap: 10rpx;

					.nick_name {
						font-weight: bold;
					}

					.noreal {
						font-size: 10px;
						padding: 10rpx 16rpx;
						background-color: #eee;
						color: gray;
						width: max-content;
					}

					.time {
						font-size: 12px;
						color: gray;
					}
				}

				.arrow {
					width: 20rpx;
					height: 20rpx;
				}
			}


			.inviting-item {
				display: flex;
				align-items: center;
				gap: 20rpx;
				border-bottom: 1px solid #eee;
				padding-bottom: 30rpx;
				position: relative;

				.avatar {
					height: 100rpx;
					width: 100rpx;
				}

				.user-info {
					display: flex;
					flex-direction: column;
					gap: 10rpx;

					.nick_name {
						font-weight: bold;
					}

					.phone {
						font-size: 10px;
						color: gray;
						width: max-content;
					}

					.time {
						font-size: 12px;
						color: gray;
					}
				}

				.arrow {
					width: 20rpx;
					height: 20rpx;
					position: absolute;
					right: 0;
				}
			}
		}

		.nopuser {
			text-align: center;
			background-color: #eee;
			padding: 40rpx;
			border-radius: 20rpx;
			color: #666;
		}
	}
</style>